﻿Imports Oracle.DataAccess.Client
Public Class cEncabezadoOrdenCompra
    Private lTipodoc As String
    Private lNumero As Integer
    Private lDoces As String
    Private lBodega As lbGlobalcom.dsInventarios.INV_BODEGASRow
    Private lTipoDocumento As lbGlobalcom.dsGlobal.GLO_TIPODOCUMENTORow

    Sub New(ByVal pTipoDoc As String, ByVal pNumero As Integer, ByVal pDoces As String)
        tipoDoc = pTipoDoc
        numero = pNumero
        doces = pDoces
    End Sub
    Public Property tipoDoc() As String
        Get
            Return lTipodoc
        End Get
        Set(ByVal value As String)
            lTipodoc = value
        End Set
    End Property

    Public Property numero() As Integer
        Get
            Return lNumero
        End Get
        Set(ByVal value As Integer)
            lNumero = value
        End Set
    End Property

    Public Property doces() As String
        Get
            Return lDoces
        End Get
        Set(ByVal value As String)
            lDoces = value
        End Set
    End Property

    Public Property fecha() As Date
        Get

        End Get
        Set(ByVal value As Date)

        End Set
    End Property

    Public Property idProveedor() As String
        Get

        End Get
        Set(ByVal value As String)

        End Set
    End Property

    Public Property sucursalGlobalcom() As String
        Get

        End Get
        Set(ByVal value As String)

        End Set
    End Property

    Public Property bodegaPara() As String
        Get

        End Get
        Set(ByVal value As String)

        End Set
    End Property

    Public Property fechaRecepcion() As Date
        Get

        End Get
        Set(ByVal value As Date)

        End Set
    End Property

    Public Property fechaPago() As Date
        Get

        End Get
        Set(ByVal value As Date)

        End Set
    End Property

    Public Property idMinPadre() As String
        Get

        End Get
        Set(ByVal value As String)

        End Set
    End Property

    Public Property centroSuministrador() As String
        Get

        End Get
        Set(ByVal value As String)

        End Set
    End Property

    ''' <summary>
    ''' identificador para relacionar pedido postpago con comcel
    ''' </summary>
    Public Property numeroPedido() As String
        Get

        End Get
        Set(ByVal value As String)

        End Set
    End Property

    Public Property iBodega() As cBodegas
        Get

        End Get
        Set(ByVal value As cBodegas)

        End Set
    End Property

    Public Property iProveedor() As cProveedores
        Get

        End Get
        Set(ByVal value As cProveedores)

        End Set
    End Property

    Public Property iTipoDocumento() As cTipoDocumento
        Get

        End Get
        Set(ByVal value As cTipoDocumento)

        End Set
    End Property

    ''' <summary>
    ''' Generada, Recibida, Cargada
    ''' </summary>
    Public Property EstadoOrden() As Integer
        Get

        End Get
        Set(ByVal value As Integer)

        End Set
    End Property

    Public Function consecutivoOrdenCompra() As String
        Dim Conn As OracleConnection = New OracleConnection(My.Settings.ConnectionString)
        Dim cmd As OracleCommand = Conn.CreateCommand
        Try
            cmd.CommandText = "GLO_CONSEC"
            cmd.CommandType = Data.CommandType.StoredProcedure
            cmd.Parameters.Add("PTIPODOC", OracleDbType.Varchar2).Value = tipoDoc
            cmd.Parameters.Add("DOCES", OracleDbType.Varchar2).Value = doces
            cmd.Parameters.Add("PNUMERO", OracleDbType.Int32).Value = numero
            Dim pNumero As OracleParameter = cmd.Parameters.Add("PNUMEROCONSEC", OracleDbType.Int32)
            pNumero.Direction = Data.ParameterDirection.Output
            Conn.Open()
            cmd.ExecuteNonQuery()
            Return pNumero.Value.ToString
        Catch ex As Exception
            cError.SalvaError(ex, "Samuel")
            Throw ex
        Finally
            Conn.Close()
        End Try
    End Function


    Public Function getConsecutivoOrdenCompra() As String
        Dim Conn As OracleConnection = New OracleConnection(My.Settings.ConnectionString)
        Dim cmd As OracleCommand = Conn.CreateCommand
        Try
            cmd.CommandText = "GLO_GETNUMEROCONSEC"
            cmd.CommandType = Data.CommandType.StoredProcedure
            cmd.Parameters.Add("PTIPODOC", OracleDbType.Varchar2).Value = tipoDoc
            cmd.Parameters.Add("DOCES", OracleDbType.Varchar2).Value = doces
            Dim pNumero As OracleParameter = cmd.Parameters.Add("PNUMEROCONSEC", OracleDbType.Int32)
            pNumero.Direction = Data.ParameterDirection.Output
            Conn.Open()
            cmd.ExecuteNonQuery()
            Return pNumero.Value.ToString
        Catch ex As Exception
            cError.SalvaError(ex, "Samuel")
            Throw ex
        Finally
            Conn.Close()
        End Try
    End Function



    Public Function validarNumero(ByVal numero As Integer) As Integer
        Dim conn As OracleConnection = New OracleConnection(My.Settings.ConnectionString)
        Dim cmd As OracleCommand = conn.CreateCommand
        Dim cantidad As Integer
        Try
            cmd.CommandText = "SELECT COUNT(*) FROM COM_ENCABEZADOORDENCOMPRA" & _
                              " WHERE NUMERO=:Pnumero"
            cmd.Parameters.Add("Pnumero", OracleDbType.Int32).Value = numero
            conn.Open()
            cantidad = cmd.ExecuteScalar
            Return cantidad
        Catch ex As Exception
            cError.SalvaError(ex, "Samuel")
            Throw ex
            Return 0
        Finally
            conn.Close()
        End Try
    End Function

    Protected Overrides Sub Finalize()

    End Sub

    Public Sub CargaDatosTipoDocumento()

    End Sub

    Public Sub CargaDatosProveeedor()

    End Sub

    Public Sub ConfiguraOrdenCompra()

    End Sub
End Class

Public Class cDetalleOrdenCompra

    Sub New(ByVal tipoDoc As String, ByVal numero As Integer)

    End Sub
    Public Property tipoDoc() As String
        Get

        End Get
        Set(ByVal value As String)

        End Set
    End Property

    Public Property numero() As Integer
        Get

        End Get
        Set(ByVal value As Integer)

        End Set
    End Property

    Public Property idProducto() As String
        Get

        End Get
        Set(ByVal value As String)

        End Set
    End Property

    ''' <summary>
    ''' codigo de producto de comcel
    ''' </summary>
    Public Property idProductoProveedor() As String
        Get

        End Get
        Set(ByVal value As String)

        End Set
    End Property

    Public Property cantidad() As Integer
        Get

        End Get
        Set(ByVal value As Integer)

        End Set
    End Property

    Public Property unidad() As String
        Get

        End Get
        Set(ByVal value As String)

        End Set
    End Property

    Public Property unidadProveedor() As String
        Get

        End Get
        Set(ByVal value As String)

        End Set
    End Property

    Public Property precioBase() As Double
        Get

        End Get
        Set(ByVal value As Double)

        End Set
    End Property

    Public Property descuento() As Double
        Get

        End Get
        Set(ByVal value As Double)

        End Set
    End Property

    Public Property idIva() As String
        Get

        End Get
        Set(ByVal value As String)

        End Set
    End Property

    Public Property iProducto() As cProducto
        Get

        End Get
        Set(ByVal value As cProducto)

        End Set
    End Property

    Public Property iIva() As cTipoIva
        Get

        End Get
        Set(ByVal value As cTipoIva)

        End Set
    End Property

    Public Property linea() As Integer
        Get

        End Get
        Set(ByVal value As Integer)

        End Set
    End Property

    Protected Overrides Sub Finalize()

    End Sub
End Class
